home *** CD-ROM | disk | FTP | other *** search
- Path: news.sunquest.com!kitk!kitk
- From: kitk@mudshark.sunquest.com (Kit Kauffmann)
- Newsgroups: comp.lang.c++
- Subject: Re: Please Help Dos Env.
- Date: Thu, 14 Mar 1996 16:22:14
- Organization: Sunquest
- Message-ID: <kitk.2134.00105F67@mudshark.sunquest.com>
- References: <Do2AAK.9KC@relay.sheridanc.on.ca>
- NNTP-Posting-Host: kkauffma.sunquest.com
- X-Newsreader: Trumpet for Windows [Version 1.0 Rev A]
-
- In article <Do2AAK.9KC@relay.sheridanc.on.ca> jason.gerrity@sheridanc.on.ca (Jason Gerrity) writes:
- >From: jason.gerrity@sheridanc.on.ca (Jason Gerrity)
- >Subject: Please Help Dos Env.
- >Date: Sun, 10 Mar 1996 17:08:43 GMT
-
- >Can someone please show me how to get a c++
- >program to set a DOS environment variable that
- >will stay resident in DOS after the c++ program
- >has terminated...?
-
- >both system and putenv only stay active for the duration
- >of the spawned process...
-
- >Please, help...
-
- >Jason
-
- >Jason.gerrity@sheridanc.on.ca
-
- Dr. Dobb's published an undocumented DOS call which allowed just this sort of
- thing (this is not C or C++, but DOS interrupts). Also, this is vintage '86
- or something, and probably doesn't work anymore, but I coded some MS assembler
- to do just this very thing at the time (providing a C interface to this rather
- difficult routine). Whether it still works with the latest DOS, who knows ;-)
-
- Anyway, here's the code - have fun:
-
- ; This routine uses an undocumented DOS interrupt (2eh) to execute a DOS
- ; command of any sort, including "internal" commands such as 'TYPE' or 'DIR'
- ; and .COM, .EXE, and .BAT files found on the PATH. The one drawback of
- ; using this function is that all non-static memory must be released before
- ; the program is used, using DOS interrupt 4A or some library function such
- ; as rstmem from Lattice. For the ramifications of this detail, see the
- ; C routine which is meant to call this routine: 'execute.c'.
- ; This routine has been adapted from routines published in the Dec. '86
- ; Dr. Dobb's by Kit Kauffmann to be compiled with MASM (I used 4.0) and
- ; called from Lattice C programs.
-
- INCLUDE DOS.MAC ; this is a set of lattice macros for setting the
- ; memory model dependent information.
-
- SETX ; determines offset of parameters
-
- PSEG ; start code area
-
- BEGIN INT2E ; establish legal function entry point
-
- PUSH BP ; save registers
- MOV BP,SP ; establish new stack frame
- PUSH ES ; needed by lattice
- PUSH DS ; ditto
- PUSH SI ; we point ds:si at command string
- PUSH DX ; although I did not had a problem with this
- MOV DL,1 ; during the alteration and debugging of these
- ; routines, not to mention learning the intricacies
- ; of stack frame manipulation, int2e is advertised
- ; to set disk write verification with dl set to 0.
- ; Admittedly, the chances are small (perhaps less
- ; than 1 in 256?), but I am an ardent believer in
- ; only one law of the universe: Murphy's Law.
-
- MOV WORD PTR CS:SAVE_SS,SS ; I know this is dirty programming, but
- MOV WORD PTR CS:SAVE_SP,SP ; seems to be no reasonable alternative
- ; because both SS & SP must be preserved
- ; as must DS and BP, which are are chewed
- ; up by this odd interrupt. For extra
- ; data on this trick, read the warning on
- ; page 317 of Norton's Programmer's Guide,
- ; in which the EXEC interrupt does similar
- ; things.
-
- MOV SI,[BP + X] ; ds already points at static data area in Lattice
- INT 2EH ; undocumented interrupt - see DDS 12/86
-
- MOV SS,WORD PTR CS:SAVE_SS ; restore the cleverly hidden stack data
- MOV SP,WORD PTR CS:SAVE_SP
-
- POP DX ; restore registers
- POP SI
- POP DS
- POP ES
- POP BP
- JMP RTN ; jump over hiding place for data
-
- SAVE_SS:DW 0 ; storage space (sneaky, huh!)
- SAVE_SP:DW 0
-
- RTN:
- RET
- INT2E ENDP
- ENDPS
- END
-
- HTH!
-
-
- Kit Kauffmann - kitk@mudshark.sunquest.com
- AKA 73363,447 (Compu$erve)
-
- Finger me for my public key
-